package com.banshuibao.bsb_android.util;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;

/**
 * Created by wangpan on 2016/12/25.
 */

public class SpannalbeUtil {
    //txt是整个字符串
//startIndex 从第几位开始
//txt.length()是在第几位结束
//col是中间的文字显示什么的颜色

    public static SpannableString AutolinkName(String txt, int startIndex,
                                               int colorNum, final Context con) {
        int col = 0;
        switch (colorNum) {
            case 0:// 黑色
                col = 0xff000000;
                break;
            case 1:// 绿色
                col = 0xff22ac38;
                break;
            case 2:// 橘色
                col = 0xffeb6100;
        }
        SpannableString spannableString = new SpannableString(txt);
        spannableString.setSpan(new ForegroundColorSpan(col), startIndex,
                txt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;

    }

    public static SpannableString AutolinkColor(String txt, int startIndex,
                                                int colorNum, int endIndex) {
        int col = 0;
        switch (colorNum) {
            case 0:// 黑色
                col = 0xff000000;
                break;
            case 1:// 绿色
                col = 0xff22ac38;
                break;
            case 2:// 橘色
                col = 0xffeb6100;
                break;
            case 3:// 红色
                col = 0xffff0000;
                break;
            case 4://黄色
                col = 0xffffff00;
                break;
        }
        SpannableString spannableString = new SpannableString(txt);
        spannableString.setSpan(new ForegroundColorSpan(col), startIndex,
                endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;

    }
}
